#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "model.h"

SOLDIER *createSoldier(char bufName[], int bufExp, char rank[], char div[], char jobCat[])
{
	//Local Definitions
	SOLDIER *pSoldier;
	
	//Statements
	pSoldier = (SOLDIER *) malloc(sizeof(SOLDIER));
	if (pSoldier == NULL) {
		printf("Unable to allocate memory. End Program\n");
		exit(1);
	}
	pSoldier->name = allocateString(bufName);
	pSoldier->experience = bufExp;
	pSoldier->rank = allocateString(rank);
	pSoldier->division = allocateString(div);
	pSoldier->jobCat = allocateString(jobCat);
	
	return pSoldier;
}

/* allocateString allocates memory for a string                      */
/* Pre:    str - a string                                            */
/* Post:   pc - a pointer that point to heap memory and store str    */
/* Return: pc - a pointer has memory and data                        */
/* Written by: Faith Or                                              */
char *allocateString(const char *str)
{
	char *pc;

	pc = (char *)malloc(strlen(str) + 1);

	if (pc != NULL)
		strcpy(pc, str);
	else{
		printf("Unable to allocate memory. End Program\n");
		exit(1);
	}

	return pc;
}//end allocateString

void createHeadNode(HEAD_NODE *headNode, HASH *hash, BST *bst, STACK *stack)
{
	//Statement
	headNode->count = 0;
	headNode->pHash = hash;
	headNode->pTree = bst;
	headNode->pStack = stack;
	
	return;
}

HEAD_NODE *iniHeadNode(void)
{
	//Local Declarations
	HEAD_NODE *headNode;
	
	//Statement
	headNode = (HEAD_NODE *) malloc(sizeof(HEAD_NODE));
	
	headNode->count = 0;
	headNode->pHash = NULL;
	headNode->pTree = NULL;
	headNode->pStack = NULL;
	
	return headNode;
}